﻿Namespace B1Data
    Public Class B1ValidValues
        Private _List As List(Of B1ValidValue) = New List(Of B1ValidValue)
        Private _Column As B1Data.B1DataColumn
        Private sql_GetValues As String = "SELECT *  FROM [dbo].[UFD1]  T0 INNER JOIN [dbo].[CUFD] T1 On T0.TableID = T1.TableID AND T0.FieldID = T1.FieldID WHERE T1.TableId = '[%0]' AND T1.AliasID = '[%1]'"

        Sub New(ByVal Column As B1Data.B1DataColumn)
            _Column = Column
            'sql_GetValues = sql_GetValues.Replace("[%0]", Column.Table.TableName).Replace("[%1]", Column.ColumnName)
        End Sub

        Public Sub LoadValues()
            Dim oRs As SAPbobsCOM.Recordset
            Dim item As B1ValidValue
            oRs = _Column.Table.SboCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
            oRs.DoQuery(sql_GetValues)
            Do Until oRs.EoF
                item = New B1ValidValue
                item.Value = oRs.Fields.Item(0).Value
                item.Description = oRs.Fields.Item(1).Value
                Add(item)
                oRs.MoveNext()
            Loop
        End Sub

        Default Public ReadOnly Property Item(ByVal i As Integer) As B1ValidValue
            Get
                Return _List(i)
            End Get
        End Property

        Public ReadOnly Property Count As Integer
            Get
                Return _List.Count
            End Get
        End Property

        Public Sub Add(ByVal item As B1ValidValue)
            _List.Add(item)
        End Sub

        Public Sub Add(ByVal Value As String, ByVal Decription As String)
            Dim item As New B1ValidValue
            item.Value = Value
            item.Description = Decription
            Add(item)
        End Sub

        Public Sub Remove(ByVal i As Integer)
            _List.RemoveAt(i)
        End Sub

        Public Sub Remove(ByVal item As B1ValidValue)
            _List.Remove(item)
        End Sub

    End Class
End Namespace

